#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ----------------------------------------------------------
# -- This's Excel Sync Handler
# -- 数据处理线程
# ****************************
# Author: lmay.Zhou
# Blog: www.lmaye.com
# Date: 2018年2月1日 18:08:32
# ----------------------------------------------------------
import datetime
from PyQt5.QtCore import pyqtSignal, QThread
from core.handler.pdf_transform import pdf_to_image


class SyncGeneratePdfThread(QThread):
    """
        SyncExecuteThread

        -- 同步执行线程
    """
    signal_out = pyqtSignal(str)

    def __init__(self, parent=None):
        super(SyncGeneratePdfThread, self).__init__(parent)
        self.threadName = "MyThread"
        self.rows = None

    def set_param(self, file_path, file_type):
        self.file_path = file_path
        self.file_type = file_type if file_type else "jpg"

    def run(self):
        """
            Synchronization Data
        """
        self.signal_out.emit("{} -->>> 开始执行 ...".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
        try:
            pdf_to_image(self.file_path, self.file_type, signal_out=self.signal_out)
        except Exception as e:
            self.signal_out.emit("{} 执行异常: {}".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), e))
            return None
        self.signal_out.emit("======================= 执行完成 =======================")
